<!DOCTYPE html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../js/jquery.min.js"></script>
    <script src="../js/jquery.easyui.min.js"></script>
    <script src="../js/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" href="../themes/icon.css">
    <link rel="stylesheet" href="../themes/default/easyui.css">
    <link rel="stylesheet" href="../css/wu.css">
    <script>
        var  selectIndex = -1;

        function hideTable(){
            $("#searchdiv").toggle();
        }
		function delDict(id){
         $.messager.confirm('确认','您确认想要删除记录吗？',function(r){
           if (r==true){
              $.ajax({
		      type:"post",//请求类型
		      url:"/kxmanage/dictDetail/delDict?id="+id, 
		      dataType:"json",//ajax接口（请求url）返回的数据类型
		      success:function(data){//data：返回数据（json对象）
		         if(data.result=="success"){
		              $.messager.alert('消息'," 删除成功！");
                      $('#productList').datagrid('reload');//删除后重新加载下
		         }else if(data.result=="error"){
		              $.messager.alert('消息'," 删除失败！");
		         }
		      }
		     }); 
           }
         })
        }
          
        $(function(){
            $("#productList").datagrid({
                url:'/kxmanage/dictDetail/findAll',
                pageNumber:1,
                pageSize:10,
                pageList:[10,20],
                pagination:true,
                checkOnSelect:true,
                columns:[[
                    {field:'ck',checkbox:true},
                    {field:'type',title:'所属类别',width:150},
                    {field:'value',title:'字典编号',width:100,
                        formatter:function (value,row,index) {
							if(value>99){
							   return '<a onclick="showDict(\'' + row.id+ '\')" style="color:blue;text-decoration:underline"  href="#">'+row.code+'</a>';
							}else if(value>10&&value<=99){
							   return '<a onclick="showDict(\'' + row.id+ '\')" style="color:blue;text-decoration:underline"  href="#">'+'0'+value+'</a>';
							}else if(value<10&&value>=1){
							   return '<a onclick="showDict(\'' + row.id+ '\')" style="color:blue;text-decoration:underline"  href="#">'+'00'+value+'</a>';
							}
                        }
                    },
                    {field:'key',title:'字典内容',width:180},
                    {field:'corporateName',title:'公司名称',width:100},
                    {field:'sortNumber',title:'排序编号',width:100,
                        formatter:function (value,row,index) {
							if(value>99){
							   return value;
							}else if(value>10&&value<=99){
							   return "0"+value;
							}else if(value<10&&value>=1){
							   return "00"+value;
							}
                        }
                    },
                    {field:'memo',title:'备注',width:100},
                    {field:'modifyUser',title:'操作员',width:100},
                    {field:'showStatus',title:'显示状态',width:100,
                        formatter:function (value,row,index) {
                          if(row.showStatus==1){
                           return "显示";
                          }else if(row.showStatus==2){
                           return "隐藏";
                          }
                        }
                    },
                    {field:'opt',title:'操作',width:100,
                        formatter:function (value,row,index) {
                            var context="<a href='#' onclick=\"delDict('"+row.id+"')\" style='color:blue;text-decoration:underline'>删除</a>&nbsp;&nbsp;" +
                                "<a href='#' onclick=\"updateDict('"+row.id+"')\" style='color:blue;text-decoration:underline'>修改</a>&nbsp;&nbsp;" 
                            return context;
                        }
                    }
                ]],
                toolbar:'#wu_toolbar', 
                onClickRow:function(index,data){
                  $(this).datagrid('unselectRow',index);
                },
                pagination:true //向后台传递参数page 和rows 
            });
         $("#search_btn").click(function(){
	     	var form=$("#form1");
  		 	$("#productList").datagrid('load',serializeForm(form));
         });
         
          $("#reset_btn").click(function(){
	        	$("#form1").form('reset');
                $("#productList").datagrid('load',{}); 
          });
          
         $.ajax({
         	type:"GET",//请求类型
		 	url:"/kxmanage/dictDetail/findalltype",//请求的url
		 	dataType:"json",//ajax接口（请求url）返回的数据类型
		 	success:function(data){//data：返回数据（json对象）
		 		if(data != null){
		 			$("#dictType").html("");
				var options = "<option value=\"\">——请选择——</option>";
				for(var i = 0; i < data.length; i++){
					options += "<option value=\""+data[i].type+"\">"+data[i].type+"</option>";
				}
				$("#dictType").html(options);
				}
		 	}
         });
          
        });
        
       	//将表单序列化
		function serializeForm(form){
			var obj={};
			$.each(form.serializeArray(),function(index){
				  if(obj[this['name']]){
					obj[this['name']]=obj[this['name']]+','+this['value']
				 }else{
				   obj[this['name']]=this['value'];
				 }
			});
			return obj;
		}  
		
        function addDict() {
            parent.addTabs("字典内容信息","goods/addDict.jsp");
        }
        
        function showDict(id) {
            parent.addTabs("字典内容信息","/kxmanage/dictDetail/showDictById?id="+id);
        } 
        function updateDict(id) {
            parent.addTabs("字典内容信息","/kxmanage/dictDetail/updateDictById?id="+id);
        }
        
        
        
    </script>

</head>
<body>
<div id="wu_toolbar">
   
    <div class="wu_toolbar_button">
        <a  href="#" onclick="hideTable()" class="easyui-linkbutton" data-options="iconCls:'icon-search'" plain="true">查询</a>|
        <a  href="#" onclick="addDict()" class="easyui-linkbutton" data-options="iconCls:'icon-add'" plain="true">添加</a>|
        <a  href="#" onclick="reload()" class="easyui-linkbutton" data-options="iconCls:'icon-communication'" plain="true">导出excal</a>
    </div>
    <div id="searchdiv" style="display: block;width: 100%;">
        <form name="form1" id="form1"> 
            <input type="hidden" id="path" value="${pageContext.request.contextPath}"/>
            <table width="100%" border="0" cellspacing="0" style="background-color:#c9dfff;" >
                <tbody><tr>
                    <td width="70"><b>检索条件:</b></td>
                    <td width="70" align="right">字典编号:</td>
                    <td width="150" align="left"><input name="dictValue" class="easyui-textbox" type="text" id="dictValue" value="" maxlength="100"></td>
                    <td width="70" align="right">字典名称:</td>
                    <td width="150" align="left"><div class="l-text-wrapper"><div class="l-text l-text-date"><input name="dictKey" type="text" id="dictKey" value="" maxlength="30" class="easyui-textbox"><div class="l-text-l"></div><div class="l-text-r"></div><div class="l-trigger"><div class="l-trigger-icon"></div></div></div></div></td>
                    <td width="70" align="right">所属类别:</td>
                    <td width="150" align="left"><div class="l-text-wrapper"><div class="l-text l-text-date">
                    <select name="dictType" id="dictType" style="width:120px;height:30px" panelHeight="150px">
                    
                    </select> 
                    </div><div class="l-trigger"><div class="l-trigger-icon"></div></div></div></div></td>
                    <td width="72">
                        <a id="search_btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'">搜索</a>
                    </td>
                    <td width="72">
                        <a id="reset_btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-refresh'">重置</a>
                    </td>
                    <td width="0"></td>
                </tr>
                </tbody>
            </table>
            <input type="hidden" id="menuCode" value="100001001">
        </form>
    </div>
</div>
<div id="productList" class="easyui-datagrid">
</div>
</body>
</html>